package com.dc.consumer;

import com.dc.rabbitmq.config.DelayRabbitConfig;
import com.dc.rabbitmq.config.RabbitMqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqConsumer {


    @RabbitListener(queues = RabbitMqConfig.QUEUE_NAME1, concurrency = "3")
    public void test(Message msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) {
        log.info("普通队列接受数据：{} ", new String(msg.getBody()));
        log.info("tag：{}", msg.getMessageProperties().getCorrelationId());
    }

    @RabbitListener(queues = DelayRabbitConfig.ORDER_QUEUE_NAME)
    public void delayTest(String msg, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) throws Exception {
        log.info("延迟队列接受数据：{}", msg);
        log.info("tag：{}", tag);
    }
}
